package 笔试;

import java.util.*;

public class 裁缝 {
    public static int result = 0;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int bigN = scanner.nextInt();
        int m = scanner.nextInt();
        String bigStr = scanner.next();
        int[] smallLen = new int[m];
        int sum = 0;
        for(int i = 0;i<m;i++) {
            smallLen[i] = scanner.nextInt();
            sum+=smallLen[i];
        }
        if(sum!=bigN) {
            System.out.println(0);
            System.exit(0);
        }
        String[] strings = new String[m];
        for(int i = 0;i<m;i++) {
            strings[i] = scanner.next();
        }
        function(strings,0,bigStr);
        System.out.println(result);
    }

    public static void function(String[] strings, int i,String bigStr) {
        if(i == strings.length) {
            StringBuilder stringBuilder = new StringBuilder();
            for (String string : strings) {
                stringBuilder.append(string);
            }
            if(bigStr.equals(stringBuilder.toString())) {
                result++;
            }
        } else {
            for(int k = i;k<strings.length;k++) {
                if(isSwap(strings,i,k)) {
                    swap(strings, i, k);
                    function(strings, i + 1, bigStr);
                    swap(strings, i, k);
                }
            }
        }
    }
    public static void swap(String[] nums,int i,int j) {
        String temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
    public static boolean isSwap(String[] nums,int i,int j) {
        for(int k = i;k<j;k++) {
            if(nums[k].equals(nums[j])) {
                return false;
            }
        }
        return true;
    }
}
